﻿using System;
using System.Collections.Generic;
using System.Text;
using Stauffware.Common.Core;
using Stauffware.Common.Time;
using System.Globalization;
using NUnit.Framework;

namespace UnitTests.Time
{
	public class TimeSpanParseTests
	{
		//=============================================================================
		// Tests that yield a value
		//
		//          input          parsed text     value D,H,M,S,F     

		[TestCase("0",				"0",			0, 0, 0, 0, 0, 
						TimeSpanParseOptions.None)]
		[TestCase("00:00:00",		"00:00:00",		0, 0, 0, 0, 0, 
						TimeSpanParseOptions.None)]
		[TestCase("23:45:01", "23:45:01",			0, 23, 45, 1, 0,
						TimeSpanParseOptions.None)]

		public static void ValueTest (string input,
									string expectedParsedText,
									int expectedDays,
									int expectedHours,
									int expectedMinutes,
									int expectedSeconds,
									int expectedMilliseconds,
									TimeSpanParseOptions options)
		{
			TimeSpan expectedValue = new TimeSpan(expectedDays, expectedHours, 
							expectedMinutes, expectedSeconds, expectedMilliseconds);

			TimeSpanParse parse = new TimeSpanParser(options).Parse(input);

			if (parse.GotValue)
				NUnit.Framework.Assert.AreEqual(expectedValue, parse.Value, "Value");

			NUnit.Framework.Assert.AreEqual(expectedParsedText, parse.ParsedText, "ParsedText");
			NUnit.Framework.Assert.AreEqual(null, parse.ErrorMessage, "ErrorMessage");
			NUnit.Framework.Assert.AreEqual(true, parse.GotValue, "GotValue");
			NUnit.Framework.Assert.AreEqual(false, parse.IsError, "IsError");
			NUnit.Framework.Assert.AreEqual(false, parse.IsEmpty, "IsEmpty");
		}

		//=============================================================================
		// Tests that yield an error.
		//
		//         input     parsed text    error 

		//[TestCase(" ", "", "invalid time; expecting digits",
		//                TimeSpanParseOptions.ParseEntireInput)]

		//public static void ErrorTest (string input,
		//                            string expectedParsedText,
		//                            string expectedError,
		//                            TimeSpanParseOptions options)
		//{
		//    TimeSpanParse parse = new TimeSpanParser(options).Parse(input);

		//    NUnit.Framework.Assert.AreEqual(expectedParsedText, parse.ParsedText, "ParsedText");
		//    NUnit.Framework.Assert.AreEqual(expectedError, parse.ErrorMessage, "ErrorMessage");
		//    NUnit.Framework.Assert.AreEqual(false, parse.GotValue, "GotValue");
		//    NUnit.Framework.Assert.AreEqual(true, parse.IsError, "IsError");
		//    NUnit.Framework.Assert.AreEqual(false, parse.IsEmpty, "IsEmpty");
		//}

		//=============================================================================
		// Tests that yield "empty".
		//
		//         input     parsed text    options 

		[TestCase("", "", TimeSpanParseOptions.None)]
	//	[TestCase("  ", "", TimeSpanParseOptions.None)]
		[TestCase("", "", TimeSpanParseOptions.ParseEntireInput)]

		public static void EmptyTest (string input,
									string expectedParsedText,
									TimeSpanParseOptions options)
		{
			TimeSpanParse parse = new TimeSpanParser(options).Parse(input);

			NUnit.Framework.Assert.AreEqual(expectedParsedText, parse.ParsedText, "ParsedText");
			NUnit.Framework.Assert.AreEqual(null, parse.ErrorMessage, "ErrorMessage");
			NUnit.Framework.Assert.AreEqual(false, parse.GotValue, "GotValue");
			NUnit.Framework.Assert.AreEqual(false, parse.IsError, "IsError");
			NUnit.Framework.Assert.AreEqual(true, parse.IsEmpty, "IsEmpty");
		}

		//=============================================================================
	}
}
